﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using VOL.Domain.IServices.MasterData;
using VOL.Entity.DomainModels;

namespace VOL.WebApi.Controllers.MasterData
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SupplierController : ControllerBase
    {
        /// <summary>
        /// 供应商管理服务
        /// </summary>
        private ISupplierServices _supplierServices;

        public SupplierController(ISupplierServices supplierServices)
        {
            _supplierServices = supplierServices;
        }

        /// <summary>
        /// 添加供应商管理
        /// </summary>
        /// <param name="supplier"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddSupplier([FromBody] Supplier supplier)
        {
            var res = await _supplierServices.AddSupplier(supplier);
            return res;
        }
        /// <summary>
        /// 供应商管理的显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<Supplier>> GetAllSupplierList()
        {
            var res = await _supplierServices.GetAllSupplierList();
            return res;
        }

        /// <summary>
        /// 更新供应商信息
        /// </summary>
        /// <param name="supplier"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateSupplier([FromBody]Supplier supplier)
        {
            var res = await _supplierServices.UpdateSupplier(supplier);
            return res;
        }

        /// <summary>
        /// 删除供应商
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<int> DeleteSupplier(int id)
        {
            var res = await _supplierServices.DeleteSupplier(id);
            return res;
        }
    }
}
